<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/2/24
 * Time: 14:49
 */
namespace App\Task;
use App\Service\SettleTradeOrderDisFeeService;
use App\Utils\CustomUtils;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;

/**
 * @Crontab(name="TradeOrderDisFeeTask", rule="0 3 *\/1 * *", callback="execute", memo="拒付处理费月结，每月初执行")
 */
class TradeOrderDisFeeTask
{

    /**
     * @Inject()
     * @var SettleTradeOrderDisFeeService
     */
    private $SettleTradeOrderDisFeeService;

    public function execute()
    {
        $startTime = time();
        CustomUtils::xzxDebug("交易拒付处理费任务执行，当前时间: " . date('Y-m-d H:i:s', $startTime));

        // 取上个月
        $statStartTime = strtotime(date('Y-m-01', strtotime("first day of last month")));
        $statEndTime = strtotime(date('Y-m-01', time()));
        $this->SettleTradeOrderDisFeeService->statAndPush($statStartTime, $statEndTime);

        $endTime = time();
        CustomUtils::xzxDebug("交易拒付处理费任务执行完成，执行耗时: " . ($endTime - $startTime));
    }

}